import Vue from 'vue'
import Vuex from 'vuex'
import API from "@/config/api.js";
Vue.use(Vuex)


var store = new Vuex.Store({
  state: {
      userinfo:""
  },
  //$store.commit
  mutations: {
    setUserInfo(state,userinfo){
      state.userinfo = userinfo;
    }
  },
  //$store.dispatch
  actions: {
    async getUserInfo({commit},params){
        // var user = await API.getUserInfo(params);
        // commit("setUserInfo",user);
        return Promise.resolve(user);
    }
  }
});

// store.subscribe((mutation )=>{
//   if(mutation.type == "setUserInfo"){
//     if(mutation.payload){
//       utils.setUserInfo(mutation.payload)
//     }else{
//       utils.clearUserInfo();
//     }
//   }
// })

export default store